#ifndef MIXIVOICE_H
#define MIXIVOICE_H

#include <QtGui/QWidget>
#include <QtGui/QSystemTrayIcon>
#include <QtCore/QList>

#include "Voice.h"

namespace Ui
{
	class mixiVoice;
}

class QMenu;
class QAction;
class QSettings;
class QNetworkAccessManager;
class QNetworkReply;
class QCloseEvent;
class QContextMenuEvent;
class QTimer;
class QLabel;
class QEvent;

class CookieJar;

class Setting
{
public:
	static const QString EMail;
	static const QString Password;
	static const QString SavePassword;
	static const QString ReloadInterval;
	static const QString AlwaysOnTop;
	static const QString NotificationShowTime;
	static const QString WindowSize;
	static const QString WindowPosition;
	static const QString VoiceFormat;
	static const QString WindowBackgroundColor;
	static const QString WindowTextColor;
	static const QString MaxVoiceCount;
	static const int MinReloadIntervalInMin;
	static const QString HiddenUsers;
	static const QString DateTimeFormat;
};

class mixiVoice : public QWidget
{
	Q_OBJECT

public:
	mixiVoice(QWidget *parent = 0);
	~mixiVoice();

protected:
	void closeEvent(QCloseEvent *);
	void contextMenuEvent(QContextMenuEvent *);
	virtual void changeEvent(QEvent *);

protected slots:
	void reload();
	void login();
	void about();

	void showSettingDialog();

	void postNewVoice();

private:
	Ui::mixiVoice *ui;

	QSettings *settings;
	QSystemTrayIcon *trayIcon;
	QMenu *trayIconMenu;
	QMenu *contextMenu;
	QAction *actDeleteSelectedVoice;

	QString postKey;

	QNetworkAccessManager *netMan;
	CookieJar *cookieJar;

	QTimer *timer;

	QLabel *voice[25];

	QList<Voice> voices;

	int selectedVoiceIndex;

	int maxVoiceCount;
	int loadingImage;

	void setupContextMenu();
	void setupUI();

	void saveSettings();
	void loadSettings();

private slots:
	void replyFinished(QNetworkReply *);

	void trayIconActivated(QSystemTrayIcon::ActivationReason);

	void clearAllVoices();
	void setVoices(const QList<Voice> &);

	void addSelectedUserToHiddenList();
	void deleteSelectedVoice();
	void replyToSelectedVoice();

	void openURL(const QString &);

	static QString htmlToPlainText(QString);
};

#endif // MIXIVOICE_H
